<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list' || $_RQ['op']=='list2'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['op']=='list'){
		$params['type']=array(0);
	}else{
		$params['type']=array(3);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 100;
	$total='';
	$fields=array('id','uniacid','title','type','status');
	$list=pdo_getslice('jy_yxw_store',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
		$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
		$params=array('uniacid'=>$_SESSION['uniacid']);
		if($_RQ['jiao_time']){
			$time_range=cfc('tools')->base64_decode($_RQ['jiao_time'],$_SESSION['base_key_str']);
			$time_range=json_decode($time_range,true);
			$return['params']['jiao_time']=$time_range;
			$between=array($time_range['tstart'],$time_range['tend']);
			$params['jiao_time between']=array($time_range['tstart'],$time_range['tend']);
		}
		$myhebaonumparams=$yesmyhebaonumparams=$hebaonumparams=$baonumparams=array('type'=>1,'status'=>1,'uniacid'=>$_SESSION['uniacid']);
		$baonumparams2=$yesfeeparams=array('type'=>array(1,2,4,5),'status'=>array(1,3,4,5),'uniacid'=>$_SESSION['uniacid']);
		$tuifeenumparams=array('type'=>array(0,1),'status'=>4,'uniacid'=>$_SESSION['uniacid']);
		$yesfenfeeparams=$fenfeeparams=array('type'=>2,'uniacid'=>$_SESSION['uniacid']);
		$memberparams['type']=32;
		$shmennumparams['type']=$shmennum2params['type']=32;
		$tingnumparams['type']=40;
		$ting2numparams['type']=42;
		$xuenumparams['type']=41;
		if(!$between){
			$memberparams['createtime >']=0;
			$shmennumparams['createtime >']=0;
			$shmennum2params['createtime >']=0;
			$tingnumparams['createtime >']=0;
			$ting2numparams['createtime >']=0;
			$xuenumparams['createtime >']=0;
			$baonumparams['jiao_time >']=0;
			$baonumparams2['jiao_time >']=0;
			$tuifeenumparams['tuidaytime >']=0;
			$hebaonumparams['jiao_time >']=0;
			$myhebaonumparams['jiao_time >']=0;
			$fenfeeparams['jiao_time >']=0;
		}else{
			$memberparams['createtime between']=$between;
			$shmennumparams['createtime between']=$between;
			$shmennum2params['createtime between']=$between;
			$tingnumparams['createtime between']=$between;
			$ting2numparams['createtime between']=$between;
			$xuenumparams['createtime between']=$between;
			$baonumparams['jiao_time between']=$between;
			$baonumparams2['jiao_time between']=$between;
			$tuifeenumparams['tuidaytime between']=$between;
			$hebaonumparams['jiao_time between']=$between;
			$myhebaonumparams['jiao_time between']=$between;
			$fenfeeparams['jiao_time between']=$between;
		}
		$hebaonumparams['workerheid >']=0;
		foreach($list as &$item){
			$worker6ids=pdo_getall('jy_yxw_worker',array('storeid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
			$worker6ids=$worker6ids?array_keys($worker6ids):-1;
			$yestuifeenumparams['worker6id']=$myhebaonumparams['workerheid']=$hebaonumparams['worker6id']=$baonumparams2['worker6id']=$shmennumparams['worker6id']=$shmennum2params['worker6id']=$tingnumparams['worker6id']=$ting2numparams['worker6id']=$xuenumparams['worker6id']=$baonumparams['worker6id']=$tuifeenumparams['worker6id']=$memberparams['worker6id']=$worker6ids;
			$item['memberall']=pdo_count('jy_yxw_workerlog',$memberparams);
			$item['shangmenall']=pdo_count('jy_yxw_workerlog',$shmennumparams);
			$item['shangmenall2']=pdo_count('jy_yxw_workerlog',$shmennum2params);
			$item['tingnum']=pdo_count('jy_yxw_workerlog',$tingnumparams);
			$item['tingnum2']=pdo_count('jy_yxw_workerlog',$ting2numparams);
			$item['xuenum']=pdo_count('jy_yxw_workerlog',$xuenumparams);
			$item['tuinum']=pdo_count('jy_yxw_tuifee_log',$tuifeenumparams);
			if($item['memberall']>0){
				$item['shangmen2rate']=price($item['shangmenall2']*100/$item['memberall']);
			}
			if($item['shangmenall']>0){
				$item['ting1rate']=price($item['tingnum']*100/$item['shangmenall']);
			}
			if($item['tingnum']>0){
				$item['ting2rate']=price($item['tingnum2']*100/$item['tingnum']);
			}
			if($item['tingnum2']>0){
				$item['xue1rate']=price($item['xuenum']*100/$item['tingnum2']);
			}
			$item['baonum']=pdo_count('jy_yxw_infee_log',$baonumparams);
			if($item['tuinum']>0){
				//$item['baonum'] -=$item['tuinum'];
			}
			$item['hebaonum']=pdo_count('jy_yxw_infee_log',$hebaonumparams)/2;
			$item['myhebaonum']=pdo_count('jy_yxw_infee_log',$myhebaonumparams)/2;
			$item['baonum']=$item['baonum']-$item['hebaonum']+$item['myhebaonum'];
			if($item['shangmenall']>0){
				$item['bao2rate']=price($item['baonum']*100/$item['shangmenall']);
			}
			$item['danfee1']=pdo_getsum('jy_yxw_infee_log',$baonumparams2,'fee');
			if($item['xuenum']>0){
				$item['bao1rate']=price($item['baonum']*100/$item['xuenum']);
			}
		}
	}
	paixu($list,'allfee','desc');
	foreach($list as $k=>&$lv){
		$lv['rank']=$k+1;
	}
	$heji=array('title'=>'合计');
	foreach($list as $k=>&$v){
		$v['rank']=$k+1+$isnum;
		$heji['memberall'] +=$v['memberall'];
		$heji['shangmenall'] +=$v['shangmenall'];
		$heji['shangmenall2'] +=$v['shangmenall2'];
		$heji['tingnum'] +=$v['tingnum'];
		$heji['tingnum2'] +=$v['tingnum2'];
		$heji['xuenum'] +=$v['xuenum'];
		$heji['baonum'] +=$v['baonum'];
		$heji['tuinum'] +=$v['tuinum'];
		$heji['danfee'] +=$v['danfee'];
		$heji['yes'] +=$v['yes'];
	}
	if($heji['memberall']>0){
		$heji['shangmen2rate']=price($heji['shangmenall2']*100/$heji['memberall']);
	}
	if($heji['shangmenall']>0){
		$heji['ting1rate']=price($heji['tingnum']*100/$heji['shangmenall']);
	}
	if($heji['tingnum']>0){
		$heji['ting2rate']=price($heji['tingnum2']*100/$heji['tingnum']);
	}
	if($heji['tingnum2']>0){
		$heji['xue1rate']=price($heji['xuenum']*100/$heji['tingnum2']);
	}
	if($heji['xuenum']>0){
		$heji['bao1rate']=price($heji['baonum']*100/$heji['xuenum']);
	}
	if($heji['shangmenall']>0){
		$heji['bao2rate']=price($heji['baonum']*100/$heji['shangmenall']);
	}
	$list[]=$heji;
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排名','type'=>'string'),
			array('name'=>'title','title'=>'门店','type'=>'string'),
			array('name'=>'shangmenall','title'=>'总接待','type'=>'string'),
			array('name'=>'tingnum','title'=>'体验','type'=>'string'),
			array('name'=>'tingnum2','title'=>'体用','type'=>'string'),
			array('name'=>'xuenum','title'=>'试用','type'=>'string'),
			array('name'=>'baonum','title'=>'成交','type'=>'string'),
			array('name'=>'tuinum','title'=>'退成交','type'=>'string'),
			array('name'=>'ting1rate','title'=>'接待-体验率','type'=>'unitstring','unit'=>'%'),
			array('name'=>'ting2rate','title'=>'体验体用率','type'=>'unitstring','unit'=>'%'),
			array('name'=>'xue1rate','title'=>'体用试用率','type'=>'unitstring','unit'=>'%'),
			array('name'=>'bao1rate','title'=>'试用成交率','type'=>'unitstring','unit'=>'%'),
			array('name'=>'bao2rate','title'=>'总成交率','type'=>'unitstring','unit'=>'%'),
		)),
		'search'=>array(
			array('name'=>'jiao_time','width'=>10,'title'=>'交费日期','type'=>'time_range'),
		)
	);
	$return['store']=pdo_getall('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['htmls']=$htmls;
	exi($return);
}
